clean.lagged + clean.lagged*ipw_clean, data= d)
con_effects <- conditional.effects(condm_clean,
x = "ipw_clean",
m = "clean.lagged",
quantiles = 100000)
ggplot(con_effects,
aes(x = m,
y = b,
ymin = lwr,
ymax = upr)) +
geom_smooth(stat = "identity",
color = "black") +
geom_hline(yintercept = 0, linetype = "dashed", color = "darkgrey") +
theme_bw() + xlim(-0.1,6) + ylim(-0.065, 0.065) +
labs(x = "Clean Industry Employment",
y = "Conditional effect of Trade Shock (Clean)")
ggsave("figures/cond_clean.jpeg", width = 400/96, height = 300/96, dpi = 600, units = "in")
# dirty
condm_dirty <- lm(pro_percentage_per_year ~ ipw_dirty + ipw_clean +
nominate_dim1 + as.factor(year) +
dirty.lagged + dirty.lagged*ipw_dirty ,data= d)
con_effects <- conditional.effects(condm_dirty,
x = "ipw_dirty",
m = "dirty.lagged",
quantiles = 10000)
ggplot(con_effects,
aes(x = m,
y = b,
ymin = lwr,
ymax = upr)) +
geom_smooth(stat = "identity",
color = "black") +
geom_hline(yintercept = 0, linetype = "dashed", color = "darkgrey") +
theme_bw() + xlim(-0.1,6) + ylim(-0.065, 0.065) +
labs(x = "Dirty Industry Employment",
y = "Conditional effect of Trade Shock (Dirty)") # cond_dirty.jpeg
ggsave("figures/cond_dirty.jpeg", width = 400/96, height = 300/96, dpi = 600, units = "in")
# E. Robustness Checks ####
## (1). Change in employment levels ####
m1d2 <- feols(pro_percentage_per_year ~ ipw + nominate_dim1 +
cleanV2
| year,
cluster = ~state_CD,
data= d)
m2d2 <- feols(pro_percentage_per_year ~ ipw + nominate_dim1 +
dirtyV2
| year,
cluster = ~state_CD,
data= d)
varod = c("Import Shock", "DW Nominate", "Delta")
### Table A3. app_tab_feols_delta_dirty ####
etable(m1d2, m2d2,  tex=F, digits =4,
dict = varn, order = varod)
## (2). IV Analysis Robustness Checks ####
# IPW and IV with five year difference imports
# Here the data starts in 1996
ds$ipw5 <- std(ds$ipw5)
ds$ipw5_IV <- std(ds$ipw5_IV)
ds$dirty.lagged <- std(ds$dirty.lagged)
ds$clean.lagged <- std(ds$clean.lagged)
ds$dc_ratio.lagged <- std(ds$dc_ratio.lagged)
m15 <- feols(pro_percentage_per_year ~ ipw5 + nominate_dim1 +
dirty.lagged + clean.lagged
| year,
cluster = ~state_CD,
data= ds)
m25 <- feols(pro_percentage_per_year ~ ipw5 + nominate_dim1 +
dc_ratio.lagged
| year,
cluster = ~state_CD,
data= ds)
m_fsFE5<- feols(ipw5 ~ ipw5_IV + nominate_dim1 + dc_ratio.lagged | year,
cluster= ~state_CD, data=ds)
m_ivFE5<- feols(pro_percentage_per_year ~ nominate_dim1 + dc_ratio.lagged
| year | ipw5 ~ ipw5_IV,
cluster = ~state_CD,
data= ds)
# Decade level
d_d <- read.csv("clean/CS_decade.csv")[,-1]
stcd <- function(data, scd){
results = data %>% mutate(
state_ab = substr({{scd}}, 1,2),
district_n = substr({{scd}}, 3,4)
) %>% mutate(district_n = dplyr::recode(district_n, "00" = "AL")) %>% #at large districts are noted as AL
mutate(
state_CD = paste(state_ab, district_n, sep="-")
)
return(results)
}
d_d <- stcd(d_d, state_CD)
# merge with the main data
d$decade <- ifelse(d$year > 1999, 2, 1)
d <- d_d %>% select(-state_ab, -district_n) %>%
left_join(d, ., by =c("decade", "state_CD"))
d$ipw_decade <- std(d$ipw_decade)
d$IV_decade <- std(d$ipw_decade_IV)
#decade level analysis
md_olsFE<- feols(pro_percentage_per_year ~ ipw_decade + nominate_dim1 + dc_ratio.lagged
| decade,
cluster = ~state_CD,
data= d)
md_fsFE<- feols(ipw_decade ~ IV_decade + nominate_dim1 + dc_ratio.lagged
| decade,
cluster= ~state_CD, data=d)
md_ivFE<- feols(pro_percentage_per_year ~ nominate_dim1 + dc_ratio.lagged
| decade | ipw_decade ~ IV_decade,
cluster = ~state_CD,
data= d)
# first stage
etable(m_fsFE5, md_fsFE)
### Table A4. app_tab_IV5 ####
varod = c( "Import", "DW Nominate", "Dirty Emp (lagged)","Clean Emp (lagged)")
etable(m15, m25, m_ivFE5, md_olsFE, md_ivFE, tex=F, digits=3, order = varod, dict = varn)
## (3). Subset analysis by Party ID of Legislators ####
d_Dem <- d %>% filter(party =="D")
d_Gop <- d %>% filter(party =="R")
mp1D <- feols(pro_percentage_per_year ~ ipw + nominate_dim1 +
dirty.lagged + clean.lagged
| year,
cluster = ~state_CD,
data= d_Dem)
mp2D <- feols(pro_percentage_per_year ~ ipw + nominate_dim1 +
dc_ratio.lagged
| year,
cluster = ~state_CD,
data= d_Dem)
mp1R <- feols(pro_percentage_per_year ~ ipw + nominate_dim1 +
dirty.lagged + clean.lagged
| year,
cluster = ~state_CD,
data= d_Gop)
mp2R <- feols(pro_percentage_per_year ~ ipw + nominate_dim1 +
dc_ratio.lagged
| year,
cluster = ~state_CD,
data= d_Gop)
### Table A5. app_tab_party ####
etable(mp1D, mp1R, mp2D, mp2R, tex=F, digits=3, order = varod, dict = varn)
## (4) Election timing ####
d <- d %>% mutate(election = as.factor(ifelse(year%%2, 1,0)))
all_m <- feols(pro_percentage_per_year ~ ipw + nominate_dim1 + dc_ratio.lagged
| year,
split = ~election,
cluster = ~state_CD,
data= d)
### Table A6. app_tab_election ####
varod = c("DW Nominate", "Share")
etable(all_m,
tex=F, digits =3, order = varod,
dict= varn)
# F. Further Discussion on Structural Change ####
dr_m <- feols(pro_percentage_per_year ~ ipw_clean_m + ipw_dirty_m + nominate_dim1 + dc_ratio.lagged_m | year,
cluster = ~state_CD,
data= d)
### Table A9. app_tab_clean ####
# To be included
varod = c("DW Nominate", "Share")
etable(dr_m,
tex=T, digits =3, order = varod,
dict= varn)
colnames(d)
#==============================
# SET UP ####
#==============================
rm(list=ls(all=TRUE))
gc()
options(stringsAsFactors = FALSE)
options(scipen = 3)
set.seed(1991)
library(tidyverse)
library(stringr)
# Loading Data
# 1. DW - nominate
dw <- read.csv("data/dw_house.csv")
setwd("/Users/riopark/Documents/01_CS/tradeshock_final")
# 1. DW - nominate
dw <- read.csv("data/dw_house.csv")
# 2. LCV Roll Call Votes
df_lcv <- read_csv("data/lcv_scraped_clean_230307.csv")[,-1]
#==============================
# Transformation ####
#==============================
# Making a data frame
congress_year <- as.data.frame(c(1991:2014))
con <- c()
for (i in 102:114){con <- c(con, rep(i,2))}
congress_year$congress <- con[1:24]
colnames(congress_year) <- c("year", "congress")
congress_year <- rbind(congress_year, c(1990, 101))
## Bring in DW data first ####
dw <- dw %>% filter(chamber == "House")
dw_s <- dw %>% select(congress, district_code, state_abbrev,
party_code, bioname, bioguide_id,
nominate_dim1, nominate_dim2) %>%
filter(congress >100 & congress <115) %>% # subset
right_join(., congress_year, by=c("congress")) %>% # adding year
filter(state_abbrev != "USA") %>%
mutate(party = case_when(
party_code == 100 ~ "D",
party_code == 200 ~ "R",
TRUE ~ "I"
))
dw_s$dist <- as.character(dw_s$district_code)
for (i in 1:nrow(dw_s)){
if (str_length(dw_s$dist[i])<2){
dw_s$dist <- paste("0", dw_s$dist[i], sep="")
}
}
dw_s$state_CD <- paste(dw_s$state_abbrev, dw_s$dist, sep = "-")
# Adjusting notation for consistency
dw_s$bioname[dw_s$bioname=="BONO, Mary"] <- "BonoMack,Mary"
## Bringing in LCV Data ####
# Subsetting LCV data to match the time frame of the trade data 1990 - 2014
lcv_sub <- df_lcv %>% filter(year >1989 & year <2015) %>% select(congress,  name, party, district)
lcv_sub_u <- unique(lcv_sub)
# Adjusting notation for consistency
lcv_sub_u$name[lcv_sub_u$congress>=112 & lcv_sub_u$name == "Payne,DonaldM."] <- "Payne,JDonald"
## Merging ####
# Lower case first names
## (i) LCV
li_n_all <- data.frame(matrix(ncol=3, nrow=0))
colnames(li_n_all) <- c("name", "last_name", "first_name")
for (i in (1:nrow(lcv_sub_u))){
li_n <- as.data.frame(t(c(lcv_sub_u$name[i], str_split_fixed(lcv_sub_u$name[i], ",", 2))))
colnames(li_n) <- c("name", "last_name", "first_name")
li_n_all <- rbind(li_n_all, li_n)
}
li_n_all$last_name_lower <- tolower(li_n_all$last_name)
lcv_sub_u <- left_join(lcv_sub_u, li_n_all, by = c("name"))
lcv_sub_u$last_name_lower <- str_trim(lcv_sub_u$last_name_lower, side= c("both"))
lcv_sub_u$last_name_clean <- stringi::stri_trans_general(lcv_sub_u$last_name_lower, "Latin-ASCII")
lcv_sub_u$f <- substr(str_trim(tolower(lcv_sub_u$first_name), side= c("both")), 1, 1)
lcv_sub_u$congress <- as.character(lcv_sub_u$congress)
## (ii) DW nominate
dw_name <- dw_s %>% select(bioname, bioguide_id)
dw_n <- data.frame(matrix(ncol=3, nrow=0))
colnames(dw_n) <- c("name", "last_name", "first_name")
for (i in (1:nrow(dw_name))){
li_n <- as.data.frame(t(c(dw_name$bioname[i], str_split_fixed(dw_name$bioname[i], ",", 2))))
colnames(li_n) <- c("name", "last_name", "first_name")
dw_n <- rbind(dw_n, li_n)
}
dw_n$last_name_lower <- str_trim(tolower(dw_n$last_name), side= c("both"))
dw_n$last_name_lower <- gsub(" ", "", dw_n$last_name_lower)
dw_n$last_name_clean <- stringi::stri_trans_general(dw_n$last_name_lower, "Latin-ASCII")
dw_name <- left_join(dw_s, dw_n, by = c("bioname" = "name"))
dw_name <- dw_name %>% unique()
dw_name$f <- substr(str_trim(tolower(dw_name$first_name), side= c("both")), 1, 1)
dw_name <- dw_name %>% select(congress, bioname, bioguide_id, last_name, last_name_lower, f,
last_name_clean, first_name,
party, state_CD, nominate_dim1, nominate_dim2)
colnames(dw_name) <- c("congress", "name", "bioguide_id", "last_name", "last_name_lower", "f",
"last_name_clean", "first_name",
"party", "district", "nominate_dim1", "nominate_dim2")
# Adjusting notation for consistency
dw_name$district[dw_name$last_name_lower=="bonner"] <- "AL-01"
dw_name$district[dw_name$last_name_lower=="nunnelee"] <- "MS-01"
dw_name$last_name_clean[dw_name$last_name_clean=="herrerabeutler"] <- "herrera-beutler"
dw_name$last_name_clean[dw_name$last_name_clean=="greenewaldholtz"] <- "waldholtz"
boehner <- as.data.frame(t(c(101, "BOEHNER, John Andrew", "B000589", "BOEHNER", "boehner", "j",
"boehner", "John Andrew", "R", "OH-57", 0.513, 0.04))) # from wikipedia
colnames(boehner) <- c("congress", "name","bioguide_id", "last_name", "last_name_lower", "f", "last_name_clean", "first_name",
"party", "district", "nominate_dim1", "nominate_dim2")
dw_name <- rbind(dw_name, boehner)
dw_name$last_name_clean[dw_name$name == "LONG, Jill Lynette"] <- "longthompson"
# Addressing duplicates
# Representatives who switch their parties have double records in the DW nominate data
dw_name <- dw_name %>% filter(!(last_name_clean=="martinez" & congress == 106 & nominate_dim1 == -0.341))
dw_name <- dw_name %>% filter(!(last_name_clean=="forbes" & congress == 106 & nominate_dim1 == 0.109))
dw_name$last_name_clean[dw_name$name == "YOUNG, Charles William (Bill)"] <- "young_cw"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Young,C.W.Bill"] <- "young_cw"
dw_name$last_name_clean[dw_name$name == "WILSON, Addison Graves (Joe)"] <- "wilson_j"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Wilson,Joe"] <- "wilson_j"
dw_name$last_name_clean[dw_name$name == "WELDON, Wayne Curtis (Curt)"] <- "weldon_c"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Weldon,W.Curtis"] <- "weldon_c"
dw_name$last_name_clean[dw_name$name == "UDALL, Thomas (Tom)"] <- "udall_t"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Udall,TomS."] <- "udall_t"
dw_name$last_name_clean[dw_name$name == "THOMPSON, Michael"] <- "thompson_m"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Thompson,Mike"] <- "thompson_m"
dw_name$last_name_clean[dw_name$name == "TAYLOR, Gary Eugene (Gene)"] <- "taylor_g"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Taylor,Gene"] <- "taylor_g"
dw_name$last_name_clean[dw_name$name == "SMITH, Larkin I."] <- "smith_li"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Smith,LarkinI."] <- "smith_li"
dw_name$f[dw_name$name == "SMITH, Larkin I."] <- "li"
lcv_sub_u$f[lcv_sub_u$name == "Smith,LarkinI."] <- "li"
dw_name$last_name_clean[dw_name$name == "SMITH, Christopher Henry"] <- "smith_ch"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Smith,ChristopherH."] <- "smith_ch"
dw_name$last_name_clean[dw_name$name == "SMITH, Lamar Seeligson"] <- "smith_ls"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Smith,LamarS."] <- "smith_ls"
dw_name$last_name_clean[dw_name$name == "SMITH, Nick H."] <- "smith_nick"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Smith,Nick"] <- "smith_nick"
dw_name$last_name_clean[dw_name$name == "SMITH, Adam"] <- "smith_adam"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Smith,Adam"] <- "smith_adam"
dw_name$last_name_clean[dw_name$name == "SCOTT, Robert C."] <- "scott_rc"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Scott,RobertC."] <- "scott_rc"
dw_name$last_name_clean[dw_name$name == "SÁNCHEZ, Linda T."] <- "sanchez_lt"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Sanchez,Linda"] <- "sanchez_lt"
dw_name$last_name_clean[dw_name$name == "RYAN, Timothy J."] <- "ryan_tj"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Ryan,Tim"] <- "ryan_tj"
dw_name$last_name_clean[dw_name$name == "ROGERS, Mike"] <- "rogers_mj"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Rogers,MikeJ."] <- "rogers_mj"
dw_name$last_name_clean[dw_name$name == "ROGERS, Harold Dallas (Hal)"] <- "rogers_hd"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Rogers,Harold"] <- "rogers_hd"
dw_name$last_name_clean[dw_name$name == "PRICE, Tom"] <- "price_t"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Price,Tom"] <- "price_t"
dw_name$last_name_clean[dw_name$name == "PETERSON, John"] <- "peterson_j"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Peterson,JohnE."] <- "peterson_j"
dw_name$f[dw_name$name == "PAYNE, Donald Milford"] <- "DM"
lcv_sub_u$f[lcv_sub_u$name == "Payne,DonaldM."] <- "DM"
lcv_sub_u$f[lcv_sub_u$name == "Payne,JDonald"] <- "d"
dw_name$last_name_clean[dw_name$name == "MORAN, James P."] <- "moran_jp"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Moran,JamesP."] <- "moran_jp"
dw_name$last_name_clean[dw_name$name == "MOORE, Dennis"] <- "moore_d"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Moore,Dennis"] <- "moore_d"
dw_name$last_name_clean[dw_name$name == "MILLER, George"] <- "miller_g"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Miller,George"] <- "miller_g"
dw_name$last_name_clean[dw_name$name == "MILLER, Jefferson B. (Jeff)"] <- "miller_j"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Miller,Jeff"] <- "miller_j"
dw_name$last_name_clean[dw_name$name == "MILLER, Candice S."] <- "miller_c"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Miller,CandiceS."] <- "miller_c"
dw_name$last_name_clean[dw_name$name == "MILLER, Brad"] <- "miller_b"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Miller,Brad"] <- "miller_b"
dw_name$last_name_clean[dw_name$name == "LEWIS, Charles Jeremy (Jerry)"] <- "lews_j"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Lewis,Jerry"] <- "lews_j"
dw_name$last_name_clean[dw_name$name == "LEWIS, John R."] <- "lewis_jr"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Lewis,JohnR."] <- "lewis_jr"
dw_name$last_name_clean[dw_name$name == "KING, Peter T."] <- "king_p"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "King,PeterT."] <- "king_p"
dw_name$last_name_clean[dw_name$name == "KENNEDY, Mark"] <- "kennedy_m"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Kennedy,MarkR."] <- "kennedy_m"
dw_name$last_name_clean[dw_name$name == "JONES, Walter Beaman, Jr."] <- "jones_wb"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Jones,Jr.,Walter"] <- "jones_wb"
dw_name$last_name_clean[dw_name$name == "JONES, Walter Beaman, Sr."] <- "jones_wb_s"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Jones,Sr.,WalterB."] <- "jones_wb_s"
dw_name$f[dw_name$name == "JONES, Walter Beaman, Sr."] <- "w"
lcv_sub_u$f[lcv_sub_u$name == "Jones,Sr.,WalterB."] <-"w"
dw_name$last_name_clean[dw_name$name == "JOHNSON, Nancy Lee"] <- "johnson_nl"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Johnson,Nancy"] <- "johnson_nl"
dw_name$last_name_clean[dw_name$name == "JOHNSON, Sam"] <- "johnson_s"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Johnson,Sam"] <- "johnson_s"
dw_name$last_name_clean[dw_name$name == "JOHNSON, Eddie Bernice"] <- "johnson_e"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Johnson,EddieBernice"] <- "johnson_e"
dw_name$last_name_clean[dw_name$name == "HASTINGS, Alcee Lamar"] <- "hastings_al"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Hastings,AlceeL."] <- "hastings_al"
dw_name$last_name_clean[dw_name$name == "GREEN, Mark"] <- "green_m"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Green,MarkA."] <- "green_m"
dw_name$last_name_clean[dw_name$name == "GREEN, Raymond Eugene (Gene)"] <- "green_g"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Green,Gene"] <- "green_g"
dw_name$last_name_clean[dw_name$name == "DIAZ-BALART, Lincoln"] <- "diaz_balart_l"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Diaz-Balart,Lincoln"] <-  "diaz_balart_l"
dw_name$last_name_clean[dw_name$name == "DAVIS, Artur"] <- "davis_a"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Davis,Artur"] <- "davis_a"
dw_name$last_name_clean[dw_name$name == "DAVIS, Danny K."] <- "davis_d"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Davis,DannyK."] <- "davis_d"
dw_name$last_name_clean[dw_name$name == "DAVIS, Jim"] <- "davis_j"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Davis,James"] <- "davis_j"
dw_name$last_name_clean[dw_name$name == "DAVIS, Thomas M., III"] <- "davis_t"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Davis,ThomasM."] <- "davis_t"
dw_name$last_name_clean[dw_name$name == "DAVIS, Susan A."] <- "davis_s"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Davis,SusanA."] <- "davis_s"
dw_name$last_name_clean[dw_name$name == "DAVIS, Lincoln"] <- "davis_l"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Davis,Lincoln"] <- "davis_l"
dw_name$last_name_clean[dw_name$name == "DAVIS, Jo Ann"] <- "davis_ja"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Davis,JoAnnS."] <- "davis_ja"
dw_name$last_name_clean[dw_name$name == "BROWN, Sherrod"] <- "brown_s"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Brown,SherrodC."] <- "brown_s"
dw_name$last_name_clean[dw_name$name == "BROWN, Henry Edward, Jr."] <- "brown_he"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Brown,HenryE."] <- "brown_he"
dw_name$last_name_clean[dw_name$name == "BRADY, Robert A."] <- "brady_r"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Brady,RobertA."] <- "brady_r"
dw_name$last_name_clean[dw_name$name == "BISHOP, Sanford Dixon, Jr."] <- "bishop_s"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Bishop,SanfordD."] <- "bishop_s"
dw_name$last_name_clean[dw_name$name == "BISHOP, Timothy H."] <- "bishop_t"
lcv_sub_u$last_name_clean[lcv_sub_u$name == "Bishop,TimothyH."] <- "bishop_t"
dw_name$f[dw_name$name == "SPEIER, Karen Lorraine Jacqueline (Jackie)"] <- "j"
dw_name$f[dw_name$name == "McKEON, Howard P. (Buck)"] <- "b"
dw_name$f[dw_name$name == "WHITFIELD, Wayne Edward (Ed)"] <- "e"
dw_name$f[dw_name$name == "KEATING, William R."] <- "b"
dw_name$f[dw_name$name == "TITUS, Alice (Dina)"] <- "d"
dw_name$f[dw_name$name == "GARRETT, Scott"] <- "e"
dw_name$f[dw_name$name == "PASCRELL, William J., Jr."] <- "b"
dw_name$f[dw_name$name == "OWENS, William"] <- "b"
dw_name$f[dw_name$name == "WHITFIELD, Wayne Edward (Ed)"] <- "e"
dw_name$f[dw_name$name == "LATTA, Robert E."] <- "b"
lcv_sub_u$f[lcv_sub_u$name == "Jones,Jr.,Walter"] <-"w"
lcv_sub_u$f[lcv_sub_u$name == "Ford,Jr.,Harold"] <-"h"
lcv_sub_u$f[lcv_sub_u$name == "Weldon,W.Curtis"] <-"c"
dw_name$f[dw_name$name == "WELDON, Wayne Curtis (Curt)"] <- "c"
dw_name$f[dw_name$name == "SHUSTER, William (Bill)"] <- "b"
dw_name$f[dw_name$name == "WILSON, Addison Graves (Joe)"] <- "j"
dw_name$f[dw_name$name == "ROE, David P. (Phil)"] <- "p"
dw_name$f[dw_name$name == "THORNBERRY, William McClellan (Mac)"] <- "m"
dw_name$f[dw_name$name == "GREEN, Raymond Eugene (Gene)"] <- "g"
dw_name$f[dw_name$name == "RIGELL, E. Scott"] <- "s"
dw_name$f[dw_name$name == "HASTINGS, Richard Norman (Doc)"] <- "d"
dw_name$f[dw_name$name == "GRIFFITH, H. Morgan"] <- "m"
dw_name$f[dw_name$name == "GOODLATTE, Robert William"] <- "b"
dw_name$f[dw_name$name == "SENSENBRENNER, Frank James, Jr."] <- "j"
dw_name$f[dw_name$name == "STARK, Fortney Hillman (Pete), Jr."] <- "p"
dw_name$f[dw_name$name == "LEWIS, Charles Jeremy (Jerry)"] <- "j"
dw_name$f[dw_name$name == "CHANDLER, A. B. (Ben)"] <- "b"
dw_name$f[dw_name$name == "TURNER, Robert L."] <- "b"
dw_name$f[dw_name$name == "BOYD, F. Allen, Jr."] <- "a"
dw_name$f[dw_name$name == "DEAL, John Nathan"] <- "n"
dw_name$f[dw_name$name == "INGLIS, Robert Durden"] <- "b"
dw_name$f[dw_name$name == "EDWARDS, Thomas Chester (Chet)"] <- "c"
dw_name$f[dw_name$name == "DELAHUNT, Bill"] <- "w"
dw_name$f[dw_name$name == "BOUCHER, Frederick C."] <- "r"
dw_name$f[dw_name$name == "EVERETT, Robert Terry"] <- "t"
dw_name$f[dw_name$name == "SALI, William"] <- "b"
dw_name$f[dw_name$name == "HASTERT, John Dennis"] <- "d"
dw_name$f[dw_name$name == "SHAW, Eugene Clay, Jr."] <- "c"
dw_name$f[dw_name$name == "FROST, Jonas Martin"] <- "m"
dw_name$f[dw_name$name == "SHOWS, Clifford Ronald"] <- "r"
dw_name$f[dw_name$name == "HORN, John Stephen (Steve)"] <- "s"
dw_name$f[dw_name$name == "RILEY, Robert"] <- "b"
dw_name$f[dw_name$name == "ARMEY, Richard Keith"] <- "d"
dw_name$f[dw_name$name == "SCARBOROUGH, Charles Joseph"] <- "j"
dw_name$f[dw_name$name == "GRUCCI, Jr., Felix J."] <- "f"
dw_name$f[dw_name$name == "SCHAFFER, Robert W."] <- "b"
dw_name$f[dw_name$name == "FRANKS, Robert Douglas"] <- "b"
dw_name$f[dw_name$name == "BARRETT, William E."] <- "b"
dw_name$f[dw_name$name == "LAZIO, Enrico A. (Rick)"] <- "r"
dw_name$f[dw_name$name == "SHUSTER, E. G. (Bud)"] <- "b"
dw_name$f[dw_name$name == "ARCHER, William Reynolds, Jr."] <- "b"
dw_name$f[dw_name$name == "McCOLLUM, Ira William, Jr. (Bill)"] <- "b"
dw_name$f[dw_name$name == "ALLARD, A. Wayne"] <- "w"
dw_name$f[dw_name$name == "DURBIN, Richard Joseph"] <- "d"
dw_name$f[dw_name$name == "ROBERTS, Charles Patrick (Pat)"] <- "p"
dw_name$f[dw_name$name == "RICHARDSON, Bill"] <- "w"
dw_name$f[dw_name$name == "Jones,Sr.,WalterB."] <- "s"
dw_name$f[dw_name$name == "SMITH, Robert C."] <- "b"
dw_name$f[dw_name$name == "NELSON, Clarence William (Bill)"] <- "b"
dw_name <- dw_name %>% filter(!(last_name_clean=="martinez" & congress == 106 & nominate_dim1 == -0.341))
dw_name <- dw_name %>% filter(!(last_name_clean=="forbes" & congress == 106 & nominate_dim1 == 0.109))
# (iii) Merging
l.n <- lcv_sub_u %>% select(congress, name, last_name_clean, district, f) %>% unique()
df_bio <- left_join(l.n, dw_name, by =c("last_name_clean"="last_name_clean", "f",
"congress"))
# checking the data
table(l.n$congress)
table(dw_name$congress)
table(df_bio$congress)
#df_bio %>% filter(is.na(nominate_dim1) == 1)
# Missing from the DW nominate data :
## Kyle Mark Takai from 105th Congress (HI)
## Harry Reid from 105th Congress
## Alan Nunnelee from 105th Congress
df_bio <- df_bio %>% filter(is.na(nominate_dim1)==0)
df_bio <- unique(df_bio)
df_bio <- df_bio %>% select( congress, name.x, last_name_clean, name.y,
nominate_dim1, nominate_dim2, bioguide_id)
colnames(df_bio) <- c("congress", "name_lcv", "last_name_clean", "name_dw",
"nominate_dim1", "nominate_dim2", "bioguide_id")
# Subsetting LCV again to fit the time frame
df_lcv <- df_lcv %>% filter(year >1989 & year <2015)
df_lcv$congress <- as.character(df_lcv$congress)
lcv <- left_join(df_lcv, df_bio, by = c("name" = "name_lcv", "congress")) %>%
filter(is.na(nominate_dim1)==0)
# name_dw : the full name as found in the DW Nominate dataset. (This is used as the 'key')
# name : this is the full name as found in the LCV dataset (that I webscraped)
# NOTE** I use last_name_clean and congress to match the names from LCV and DW Nominate.
# Cleaning up the merged data ####
# (1) Redistricting issue
lcv <- lcv %>% filter(!(name == "Collins,MichaelAllen" & district == "GA-03" & year == 2001)) #GA-03 switched to GA-08
lcv <- lcv %>% filter(!(name == "Houghton,Amory" & district=="NY-31" & year == 2001)) # NY-29 to NY-31
lcv <- lcv %>% filter(!(year == 1994 & district=="OK-AL"))
lcv <- lcv %>% filter(!(name == "Linder,Johny" & district=="GA-07" & congress == 107)) # GA 07 - GA 11
lcv <- lcv %>% filter(!(name == "Linder,John" & district=="GA-07" & congress == 107)) # GA 07 - GA 11
lcv <- lcv %>% filter(!(name == "Isakson,JohnnyH." & district == "GA-AL"))
lcv <- lcv %>% filter(!(name == "Johnson,Nancy" & district == "CT-05" & year == 2001)) # CT-06 to CT-05
# (2) Name Duplicates
lcv <- lcv %>% filter(!(name == "Duncan,Jeff" & bioguide_id == "D000533"))
lcv <- lcv %>% filter(!(name == "Duncan,Jr.,JohnJ." & bioguide_id == "D000615"))
# (3) Party switches (they have duplicate dw nominate scores)
## Party Switches
lcv <- lcv %>% filter(!(name == "Goode,VirgilH." & congress == "106" & nominate_dim1 == "0.583"))  # keeping him as DEM for 106th congress
lcv <- lcv %>% filter(!(name == "Goode,VirgilH." & congress == "107" & nominate_dim1 == "0.583")) # and as GOP
lcv <- lcv %>% filter(!(name == "Deal,Nathan" & congress == "104" & nominate_dim1 == "0.581"))
lcv <- lcv %>% filter(!(name == "Griffith,Parker" & congress == "111" & nominate_dim1 == "0.385")) # keeping him as DEM bc he was elected as DEM
lcv <- lcv %>% filter(!(name == "Hall,Ralph" & congress == "108" & nominate_dim1 == "0.096"))
lcv <- lcv %>% filter(!(name == "Hayes,JamesAllison" & congress == "104" & nominate_dim1 == "0.336"))
lcv <- lcv %>% filter(!(name == "Laughlin,GregoryH." & congress == "104" & nominate_dim1 == "0.462"))
lcv <- lcv %>% filter(!(name == "Parker,Michael" & nominate_dim1 == "0.341" & congress == "104"))
lcv <- lcv %>% filter(!(name == "Shuster,Bill" & nominate_dim1 == "0.374" & congress == "107"))
lcv <- lcv %>% filter(!(name == "Tauzin,WilliamJ." & nominate_dim1 == "0.341" & congress == "104"))
lcv <- unique(lcv)
#write.csv(lcv, "clean/lcv_dw.csv")
# subsetting it for only "env" bills in a strict sense
lcv.s <- lcv %>% filter(climate_change ==1 | clean_energy == 1 |
dirty_energy ==1 | air == 1 | water == 1 )
# Per Year ####
# calculating the percentage of pro environments per year
n_year_bill <- lcv.s %>% select(year, url) %>% unique() %>% group_by(year) %>% tally()
colnames(n_year_bill) <- c("year", "n_bill_per_year")
# Year-Legislator Format ####
year_legis <- lcv.s %>% select(year, name, pro_env) %>%
group_by(name, year) %>% tally(pro_env) %>%
full_join (., n_year_bill, by="year") %>%
mutate(pro_percentage_per_year = n / n_bill_per_year) %>%
rename(total_pro_env = n)
colnames(year_legis)
# Merge it back to the bigger data
# Getting rid of bill level information
l <- lcv.s %>% select(district, congress, year, bioguide_id, name,
nominate_dim1, nominate_dim2, party) %>%
unique() %>% left_join(year_legis, ., by = c("name", "year"))
colnames(l)
range(l$total_pro_env)
# yearly data
d <- read.csv("clean/cs_dta_all.csv")[,-1]
colnames(d)
